﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐 
    //
    // 文件名：UserLock.cs
    // 文件功能描述：用户，用户锁定;初始化密码
    // 创建标识：吕海乐2009-03-12
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：页面作废 2009-6-5 李刚
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using HZ.DrugTrade.Web;
using HZ.DrugTrade.Model;

using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using System.Collections.Generic;

namespace HZ.DrugTrade.Web.Admin
{
    public partial class UserLock : BasePage
    {
        public UserLock()
        {
            this.ModuleNo = "";
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                string userId = Request["uid"].ToString();
                IBLL_User iu = Factory.BLL_User();
                //绑定用户基本信息
                User user = iu.GetUserByUserID(userId);
                if (user != null)
                {
                    lblUserId1.Text = user.UserID;
                    txtUserName.Text = user.UserName;
                    txtIsUsing.Text = user.IsUsing.ToString();
                    if (user.IsUsing == true)
                    {
                        lblIsUsing.Text = "未锁定";
                        btnUserLock.Text = "锁定";
                    }
                    else
                    {
                        lblIsUsing.Text = "已锁定";
                        lblIsUsing.ForeColor = System.Drawing.Color.Red;
                        btnUserLock.Text = "解锁";
                    }
                }
                else
                {
                    this.PageError("参数错误", "UserList.aspx");
                }

            }

        }

        /// <summary>
        /// 用户锁定，解锁
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUserLock_Click(object sender, EventArgs e)
        {
            string userId = Request["uid"];
            IBLL_User iu = Factory.BLL_User();

            //判定用户锁定、解锁情况
            string flag = btnUserLock.Text;
            if (flag == "锁定")
            {
                if (iu.LockUser(userId))
                {
                    btnUserLock.Text = "解锁";
                    PageInfo("用户已被锁定！", "");

                }
                else
                {
                    PageError( "锁定失败！","");
                }
                   
            }
            else
            {
                if (iu.UnblockUser(userId))
                {
                    btnUserLock.Text = "锁定";
                    PageInfo("用户已被解锁！", "");
                }
            }

        }

        /// <summary>
        /// 初始化密码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnInit_Click(object sender, EventArgs e)
        {
            string userId = Request["uid"];
            IBLL_User iu = Factory.BLL_User();
            if (!string.IsNullOrEmpty(userId))
            {
                if (iu.InitPassword(userId.Trim(), Constants.USER_DEFAULT_PWS ))
                {
                    PageInfo("用户密码已被初始化为！" + Constants.USER_DEFAULT_PWS, "");
                }
                else
                {
                    PageError("密码初始化失败", "");
                }
            }
            else
            {
                PageError("参数不正确", "");
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string userId = Request["uid"];
            if (!string.IsNullOrEmpty(userId))
            {
                User user = new User();
                user.UserID = userId.Trim();
                user.UserName = this.txtUserName.Text.Trim();
                user.IsUsing = Convert.ToBoolean(this.txtIsUsing.Text);

                IBLL_User iu = Factory.BLL_User();
                int result = iu.UpdateUser(user);

                if (result == 1)
                {
                    PageInfo("用户信息更新成功", "UserList.aspx");
                }
                else
                {
                    PageError("更新失败","");
                }

            }
            else {
                PageError("参数不正确", "");
            }

        }
    }
}
